package com.qhhc.enums;

import java.util.HashMap;
import java.util.Map;

public enum Status {
    pending("0", "pending"),
    confirmed("1", "confirmed"),
    completed("2", "completed"),
    cancelled("3", "cancelled");

    private final String value;  // 数据库存储的值（"0", "1", "2", "3"）
    private final String description;  // 描述字符串（"pending", "confirmed", ...）

    // 正向映射：value → Status
    private static final Map<String, Status> valueToStatusMap = new HashMap<>();

    // 逆向映射：description → Status
    private static final Map<String, Status> descriptionToStatusMap = new HashMap<>();

    static {
        for (Status status : Status.values()) {
            valueToStatusMap.put(status.value, status);
            descriptionToStatusMap.put(status.description, status);
        }
    }

    Status(String value, String description) {
        this.value = value;
        this.description = description;
    }

    // 通过 value（"0", "1", ...）获取枚举
    public static Status fromValue(String value) {
        return valueToStatusMap.get(value);
    }

    // 通过 description（"pending", "confirmed", ...）获取枚举
    public static Status fromDescription(String description) {
        return descriptionToStatusMap.get(description.toLowerCase()); // 不区分大小写
    }

    // 获取枚举对应的 value（"0", "1", ...）
    public String getValue() {
        return value;
    }

    // 获取枚举对应的 description（"pending", "confirmed", ...）
    public String getDescription() {
        return description;
    }
}